﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace HRdex_Final.Employee
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Emp(object sender, EventArgs e)
        {
            Session["empID"] = gvEmpList.SelectedDataKey.Value.ToString();
            Server.Transfer("~/Employee/empForm.aspx");
        }

        protected void btnsrch_Click(object sender, EventArgs e)
        {
            string sqlc;
            if (ddlsrch.SelectedIndex == 1)
            {
                sqlc = "SELECT formEmployees.EmployeeID, " +
                "formEmployees.LastName + ', ' + formEmployees.FirstName + ' ' + formEmployees.MiddleName AS Name, " +
                "catPositions.catPositionsName AS Position, catDepartment.DepartmentName AS Department, " +
                "formEmployees.ContactNo AS [Contact No], formEmployees.Email FROM formEmployees " +
                "INNER JOIN catPositions ON formEmployees.catPositionsID = catPositions.catPositionsID INNER JOIN " +
                "catDepartment ON formEmployees.DeptID = catDepartment.DeptID " +
                "WHERE (formEmployees.EmployeeID like '%" + txtsrch.Text + "%')";
            }
            else
            {
                sqlc = "SELECT formEmployees.EmployeeID, " + 
                "formEmployees.LastName + ', ' + formEmployees.FirstName + ' ' + formEmployees.MiddleName AS Name, " + 
                "catPositions.catPositionsName AS Position, catDepartment.DepartmentName AS Department, " + 
                "formEmployees.ContactNo AS [Contact No], formEmployees.Email FROM formEmployees " + 
                "INNER JOIN catPositions ON formEmployees.catPositionsID = catPositions.catPositionsID INNER JOIN " + 
                "catDepartment ON formEmployees.DeptID = catDepartment.DeptID " + 
                "WHERE (formEmployees.LastName + ', ' + formEmployees.FirstName + ' ' + formEmployees.MiddleName like '%" + txtsrch.Text + "%')";
            }
            EmpList.SelectCommand = sqlc;
            
        }
    }
}